#define MAX_LIGHTS 8

#define DIRECTIONAL 1
#define POINT 2
#define SPOT 3




uniform int lightCountInt;
uniform float lightCountFloat;

//////////////////////////// shading /////////////////////////////

varying vec4 color;
varying vec3 normal;
varying vec3 lightDirection[MAX_LIGHTS];
uniform int lightType[MAX_LIGHTS];


//////////////////////////// cel /////////////////////////////

uniform bool cel;





////////////////////////// shadows ///////////////////////////

uniform bool mapShadow;
varying vec4 shadowTexCoord[MAX_LIGHTS];
uniform int farPlane;






void main(){


  color= gl_Color;

  vec4 eyeVertex= gl_ModelViewMatrix*gl_Vertex;


///////////////////////// shadows ///////////////////////////

  if(mapShadow){

    for(int i= 0; i<MAX_LIGHTS; i++){		
      if(i<lightCountInt && (lightType[i] == DIRECTIONAL || lightType[i] == SPOT)){
        shadowTexCoord[i]= gl_TextureMatrix[i+1]*eyeVertex;	
      }
    }
  }



////////////////////////// shading ///////////////////////////



//////////////////////////// cel /////////////////////////////
	

  for(int i= 0; i<MAX_LIGHTS; i++){	
    if(i<lightCountInt){
      vec4 lightPosition= gl_LightSource[i].position;
      if(lightType[i]==DIRECTIONAL){
        lightDirection[i]= lightPosition.xyz*-1.0;
      }
      else if(lightType[i]==POINT || lightType[i]==SPOT){
        lightDirection[i]= normalize((lightPosition-eyeVertex).xyz);
      }
    }
  }

  normal = normalize(gl_NormalMatrix*gl_Normal);		

  gl_Position = ftransform();
}
